/*----------------------------------------------------------------------
  - File name      : pwm.c
  - Author         : Liu Chao
  - Update date    : 2020-07-31                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: 
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/

#include "pwm.h"
#include "tim.h"
#include "pid.h"

/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/
extern PID CTB_PIDX; //Control the ball of PID X-axis
/*-----------------------------------------------------------------------
|                               FUNCTION                                |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: PWM init function                        |
| @param      : PID CTB_PIDX,PID CTB_PIDY                |
| @return     : None                                     |
--------------------------------------------------------*/
  
void PWM_Init(void)
{
  HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_2);
}

/*--------------------------------------------------------
| @Description: PID to PWM output function               |
| @param      : PID CTB_PIDX,PID CTB_PIDY                |
| @return     : None                                     |
--------------------------------------------------------*/
  
void PWM_Out(double PWMX)
{
  /*
    duty cycle: 1 ---- 0.9 angle 
    
    Minimum duty cycle:5 ----    0 angle
    Medium duty cycle :15 ----  90 angle
    Maximum duty cycle:25 ---- 180 angle
    
  */

  //PWM1 ---B3
  __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, 200 - PWMX); //Parameter: timer,channel,duty

}  




/*-------END OF FLIE--------(C) COPYRIGHT Gevico Electronics-----------*/
